package com.jtjrenren.android.taxi.driver.base;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.jtjrenren.android.taxi.driver.manger.AppManger;

import com.jtjrenren.android.taxi.driver.utils.UIHelper;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/3/1.
 */
public abstract class BaseActivity extends AppCompatActivity {
    protected Handler handler;

    private PowerManager.WakeLock wakeLock = null;

    public abstract int getLayoutID();

    public abstract void init();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutID());
        ButterKnife.bind(this);
        init();
        initPowerManger();
    }

    @Override
    protected void onResume() {
        super.onResume();
        AppManger.getInstance().currentActivity = this;
//        LogUtil.log("push","个推初始化_activity:"+this.toString());
//        PushManager.getInstance().initialize(this.getApplicationContext());
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (wakeLock != null)
            wakeLock.release();
    }

    protected void initPowerManger() {
        //POWER_SERVICE：电源的服务
        PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
        //保持CPU 运转，保持屏幕和键盘灯都高亮显示。
        wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
        wakeLock.acquire();
    }

    //handler处理
    protected void initHandler() {
        if (handler == null)
            handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    handMsg(msg);
                }
            };
    }

    protected void handMsg(Message msg) {
    }

    //界面展示
    protected void displayShort(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    private ProgressDialog proDialog;

    protected void showProDialog(String title, String desc, boolean isoutCancle) {
        if (proDialog == null)
            proDialog = UIHelper.getProDialog(this, title, desc, isoutCancle);
        proDialog.show();
    }

    protected void showProDialog(String title, String desc) {
        showProDialog(title, desc, true);
    }

    protected void disProDialog() {
        if (proDialog != null)
            proDialog.dismiss();
    }
}
